package com.example.plusz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.plusz.entity.Clazz;
import com.example.plusz.entity.Student;
import com.example.plusz.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.w3c.dom.ls.LSInput;

import java.util.List;
import java.util.Map;

/**
 * @ClassName StudentController
 * @Description TODO
 * @Author HP
 * @Date 17:43 2022/7/21
 * @Version 1.0
 **/
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping("/findAll")
    private List<Student> findAll(){
        return studentService.list(null);
    }
    @RequestMapping("/findById")
    private Student  findById(@RequestParam Long id){
        return studentService.getById(id);
    }
    @RequestMapping("/fuzzyQuery")
    private List<Student> fuzzyQuery(@RequestBody Student student){
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("sid",student.getSid()).or()
                .like("sname",student.getSname()).or()
                .like("sex",student.getSex()).or()
                .like("snum",student.getSnum());
        List<Student> list =studentService.list(queryWrapper);
        return list;
    }

    @RequestMapping("/PagingQuery")
    private List<Student> PagingQuery(){
        Page<Student> page = new Page<>(1,6);
        return studentService.page(page,null).getRecords();
    }
    @RequestMapping("/addStudent")
    private String addStudent(@RequestBody Student student){
        String str=new String();
        if (studentService.save(student)){
            str = "添加成功";
            return str;
        }
        str = "添加失败";
        return str;
    }
    @RequestMapping("/updateStudent")
    private String updateStudent(@RequestBody Student student){
        String str;
        if (studentService.updateById(student)){
            str = "修改成功";
            return str;
        }
        str = "修改失败";
        return str;
    }
    @RequestMapping("/delStudent")
    private String delStudent(@RequestBody Long sid){
        String str;
        if (studentService.removeById(sid)){
            str = "删除成功";
            return str;
        }
        str = "删除失败";
        return str;
    }
    @RequestMapping("delStudentByIds")
    private String delStudentByIds(@RequestBody List<Long> list){
        String str;
        if (studentService.removeByIds(list)){
            str = "删除成功";
            return str;
        }
        str = "删除失败";
        return str;
    }


}
